/**
 * Created by alice on 2017/5/02 0001
 */
;-function (window) {
    "use strict";
    //TODO 预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        layer: null,
        page_size: 2
    };
    //TODO 初始化的方法写这里面
    var init = function () {
        init_ready();//加载预设变量
        init_event();
        function init_event() {//TODO 初始化页面事件
            var table = $('#table');
            if (result.length>ready.page_size) {
                result.length=ready.page_size;
            }
            table.bootstrapTable({
                columns: [{
                    field: 'Number',
                    title: '序号',
                    width: '5.3%',
                    formatter: function (value, row, index) {
                        return (index + 1) > 9 ? index + 1 : '0' + (index + 1);
                    }
                }, {
                    field: 'archives',
                    title: '案号',
                    width: '25.4%'
                }, {
                    field: 'createDate',
                    title: '立案时间',
                    width: '10.3%',
                    formatter: function (result) {
                        var date = new Date(result);
                        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                    }
                }, {
                    field: 'category',
                    title: '案件类型',
                    width: '14.7%',
                    formatter: function (result) {
                        switch (result) {
                            case 'a1':
                                return '刑事';
                                break;
                            case 'a2':
                                return '民事';
                                break;
                            case 'a3':
                                return '行政';
                                break;
                            case 'a4':
                                return '赔偿';
                                break;
                            case 'a5':
                                return '执行';
                                break;
                            case 'a6':
                                return '信访';
                                break;
                            case 'a7':
                                return '其他';
                                break;
                            default :
                                return '未知';
                        }
                    }
                }, {
                    field: 'name',
                    class: 'nowarp',
                    title: '案件名称',
                    width: '24%'
                }, {
                    field: 'uid',
                    title: '排期'
                }, {
                    field: 'courtName',
                    title: '法院'
                }],
                onClickRow: function (row) {
                    console.log(row, row.status, row.status < 2);
                    window.location.href = r.base_path +'major_case/detail?uid='+ row.uid
                },
                data:result
            });
            table.bootstrapTable("hideLoading", "true");
            table.bootstrapTable("hideColumn", "uid");
            table.bootstrapTable("hideColumn", "courtId");

            Class.page(1,Math.ceil(count/ready.page_size),Class.count_major);
        }

        function init_ready() {//TODO 初始化预设值
            layui.use('layer', function () {
                ready.layer = layui.layer;
            });
        }
    };
    //TODO 内部调用的方法写这里
    var Class = {
        count_major: function (page) {
            $("#loading").show();
            $.get(r.base_path + "major/selectMajorCase", {
                page:page,
                pageSize:ready.page_size
            }, function (result) {
                $("#loading").hide();
                var table = $('#table');
                if (result&&result.code==0) {
                    if (result.data.count==0) {
                        table.html('<span class="context-white context-span">暂无案件</span>');
                        Class.page(1, 1, null);
                    }else {
                        table.bootstrapTable("load", result.data.result);
                        Class.page(page, Math.ceil(result.data.count / ready.page_size), Class.count_major);
                    }
                }
            }, 'json');
        },
        select_major: function (page_no) {
            $.get(r.base_path + 'major/findMajorInfo', {
                page: page_no,
                pageSize: ready.page_size
            }, function (result) {
                var table = $('#table');
                if (result.status == 0) {
                    table.show();
                    if (result.data.length == 0) {
                        // $(".row-no-padding").append('<span>暂无开庭信息</span>');
                    } else {
                        table.bootstrapTable("load", result.data);
                    }
                    // table.hide();
                }
                $('#loading').hide();
            }, 'json').fail(function () {
                $('#loading').hide();
            });
        },
        page: function (now, totalPages, callback) {
            base.pagination('#_page', {
                currentPage: now,
                totalPages: totalPages,
                onPageClicked: function (page) {
                    callback(page);
                }
            });
        }
    };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {};
}(window);

